#ifndef DIUTILS_H
#define DIUTILS_H

#include <QByteArray>
#include <QFile>
#include <QProgressDialog>
#include <QApplication>

struct QFileGuard {
    QFile& file_;

    QFileGuard(QFile& file) : file_(file) { }
    QFileGuard(QFile& file, QFile::OpenMode flag) : file_(file) {file_.open(flag);}
    bool isOpened(void) {return file_.isOpen();}
    ~QFileGuard() { if (file_.isOpen()) file_.close(); }
};

inline char toHexLower(uint value) { return "0123456789abcdef"[value & 0xF]; }
QByteArray toHex(const QByteArray& ba, char separator, int count = -1);
qint64 backwardFind(QFile& file, const QByteArray& ba, qint64 from);
qint64 forwardFind(QFile& file, const QByteArray& ba, qint64 from);

#endif // DIUTILS_H
